
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmSeleccionServidores.java
 *
 * Created on 19/06/2011, 04:43:01 PM
 */

/**
 *
 * @author Mario
 */
public class frmSeleccionServidores extends javax.swing.JFrame {

    /** Creates new form frmSeleccionServidores */
    private List<Servidor> listServidores;
    //private List<String> listNameServidores;
    //private String[] stringMostrar;
    private servidorDao servidorDao;
    private DefaultComboBoxModel comboServidores = new DefaultComboBoxModel();
    private int index = 1;

    public frmSeleccionServidores() {
        try {
            initComponents();
            servidorDao = new servidorDao();
            listServidores = servidorDao.getListaServidoresActivos();
            llenar(comboServidores);
            //stringMostrar= null;
        } catch (SQLException ex) {
            Logger.getLogger(frmSeleccionServidores.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void llenar(DefaultComboBoxModel combotmp){
        //List<Servidor> listSer;
        Iterator iter = listServidores.iterator();
        //combotmp.addElement("Selecciona servidor");
        while(iter.hasNext()){
            Servidor ser = (Servidor) iter.next();
            System.out.println(ser.getIp_servidor());
            combotmp.addElement(ser.getIp_servidor());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jComboBoxServidores = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel("..");
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jComboBoxServidores.setModel(comboServidores);
        jComboBoxServidores.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxServidoresItemStateChanged(evt);
            }
        });
        jComboBoxServidores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxServidoresActionPerformed(evt);
            }
        });

        jButton1.setText("Mostrar Servicios");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addContainerGap(115, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jComboBoxServidores, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(79, Short.MAX_VALUE)))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBoxServidores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(47, 47, 47)
                .addComponent(jButton1)
                .addContainerGap())
        );

        jLabel1.getAccessibleContext().setAccessibleDescription("null");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxServidoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxServidoresActionPerformed
        // TODO add your handling code here:
        //jLabel1.setText("servidorses");
    }//GEN-LAST:event_jComboBoxServidoresActionPerformed

    private void jComboBoxServidoresItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxServidoresItemStateChanged
        // TODO add your handling code here:
        //Servidor ser = (Servidor)
        int inde = jComboBoxServidores.getSelectedIndex();
        jLabel1.setText(listServidores.get(inde).getIp_servidor());
    }//GEN-LAST:event_jComboBoxServidoresItemStateChanged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmSeleccionServidores().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBoxServidores;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

}
